var theme = 'black';
var deviceMeasure = {};
//$(document).ready(function () {  等价于 $(function() {
$(document).ready(function() {


});


$(function() {
    initToolBar();

    initHistoryTable();

    $(window).load(function() {
        createMeasureSelectWindow(); //使用对话框 ，比用popump 弹窗对窗口大小适应比较好一些。
        initTreeGrid();
        initListBox();
        initDeviceMeasureList();
        initFilterWind("量测过滤");
    });

    //jqgridtest();


});

//初始化 量测过滤属性设置对话框

function initFilterWind(title) {
    //初始化量测属性条件选择下拉框
    initFilterComboBox = function() {
        var filterComb = [{
                "filterName": "无",
                "filterValue": NaN
            }, {
                "filterName": "大于",
                "filterValue": ">"
            }, {
                "filterName": "小于",
                "filterValue": "<"
            }, {
                "filterName": "等于",
                "filterValue": "="
            }, {
                "filterName": "大于等于",
                "filterValue": ">="
            }, {
                "filterName": "小于等于",
                "filterValue": "<="
            }]
            // prepare the data
        var source = {
            datatype: "array",
            datafields: [{
                name: 'filterName'
            }, {
                name: 'filterValue'
            }],
            localData: filterComb,
            async: false
        };
        var dataAdapter = new $.jqx.dataAdapter(source);
        $("#filter1").jqxComboBox({
            selectedIndex: 0,
            source: dataAdapter,
            displayMember: "filterName",
            valueMember: "filterValue",
            width: 150,
            height: 25,
            theme: theme,
            renderSelectedItem: function(index, item) {
                var item = dataAdapter.records[index];
                if (item != null) {
                    // var label = item.name + ", " + item.countryName + ", " + item.adminName1;
                    return item.filterName;
                }
                return "";
            }
        });
        $("#filter2").jqxComboBox({
            selectedIndex: 0,
            source: dataAdapter,
            displayMember: "filterName",
            valueMember: "filterValue",
            width: 150,
            height: 25,
            theme: theme
        });

    }
    //初始化量测属性关系选择项
    initFilterComboBoxn = function() {
        var filterComb = [{
                "filterName": "none",
                "filterValue": NaN
            }, {
                "filterName": "and",
                "filterValue": "and"
            }, {
                "filterName": "or",
                "filterValue": "or"
            }]
            // prepare the data
        var source = {
            datatype: "array",
            datafields: [{
                name: 'filterName'
            }, {
                name: 'filterValue'
            }],
            localData: filterComb,
            async: false
        };
        var dataAdapter = new $.jqx.dataAdapter(source);
        $("#filter-n").jqxComboBox({
            selectedIndex: 0,
            source: dataAdapter,
            displayMember: "filterName",
            valueMember: "filterValue",
            width: 100,
            height: 25,
            theme: theme
        });
    }
    initFilterComboBox();
    initFilterComboBoxn();

    $("#Cancel").jqxButton({
        theme: theme
    });
    $("#Save").jqxButton({
        theme: theme
    });
    $("#filter1-arg").jqxInput({
        placeHolder: "Enter text",
        theme: theme,
        width: 150,
        height: 25,
        renderer: function(itemValue, inputValue) {
            // alert(itemValue);
            //            alert(inputValue);
            //  if(!itemValue)
            return "ddddddddddd";
            return value;
        }
    });
    $("#filter2-arg").jqxInput({
        placeHolder: "Enter text",
        theme: theme,
        width: 150,
        height: 25
    });
    //初始化量测选项window
    //position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 },
    $("#filter-editor").jqxWindow({
        width: 210,
        title: title,
        theme: theme,
        resizable: false,
        isModal: true,
        autoOpen: false,
        cancelButton: $("#Cancel"),
        modalOpacity: 0.01,
        initContent: function() {

        }
    });

}



//显示window 并设置window初始值
function filterWindShow(row, obj) {

    var dataRecord = $("#allowselect").jqxGrid('getrowdata', row);

    //"measureName": "高压母线", "measureFilter": "1",
    //  $("#firstName").val(dataRecord.measureName);
    //  $("#firstName").val(dataRecord.measureName);
    //{"filter1":"","filter1_arg":""}
    $("#filter-editor").jqxWindow("open");
    //position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 },
    $('#filter-editor').jqxWindow({
        position: {
            x: obj.screenX - obj.offsetX,
            y: obj.clientY
        }
    });
    $("#filter-editor").jqxWindow("setTitle", dataRecord.measureName);

    var filter = dataRecord.measureFilter;
    if (typeof(filter) == "string") //表格赋初值的时候，使用的是字符串方式。需要转换为filter。
        filter = JSON.parse(filter);
    $("#filter1,#filter2,#filter-n").jqxComboBox('clearSelection'); //清楚combobox的已经选择的项。

    $("#filter1").jqxComboBox("val", filter.filter1);
    $("#filter2").jqxComboBox("val", filter.filter2 ? filter.filter2 : NaN);
    $("#filter-n").jqxComboBox("val", filter.filter_n ? filter.filter_n : NaN);

    var filter_arg1 = $("#filter1-arg").jqxInput("val", filter.filter1_arg ? filter.filter1_arg : "");
    var filter_arg1 = $("#filter2-arg").jqxInput("val", filter.filter2_arg ? filter.filter2_arg : "");

    //设置确定按钮事件,保存数据到表格中
    //设置大于小于 arg 必须为数字
    //设置contain arg 必须为字符
    //设置等于arg 必须为数字
    $("#Save").one("click", function() {
        var VALUEFIELD = "rtvalue";
        // var str = "hello{0}{1}".format('world','haha');
        var resultField = {};
        //combox 直接获取值，可能不正确----combobox可以人为的输入数据，导致获取的是不对的。
        //var item = $("#jqxComboBox").jqxComboBox('getSelectedItem');当认为输入的数据通过该方法将得到null
        if (($("#filter1").jqxComboBox('getSelectedItem') != null) && ($("#filter1-arg").jqxInput("val") !== "") && $("#filter1").jqxComboBox('val')) //条件和条件参数必须同时有效
        {
            resultField["filter1"] = $("#filter1").jqxComboBox('val');
            resultField["filter1_arg"] = $("#filter1-arg").jqxInput("val");

            if (($("#filter-n").jqxComboBox("getSelectedItem") != null) && $("#filter-n").jqxComboBox('val')) //条件连接符是否选择
            {

                if (($("#filter2").jqxComboBox('getSelectedItem') != null) && ($("#filter2-arg").jqxInput("val") !== "") && $("#filter2").jqxComboBox('val')) {
                    resultField["filter_n"] = $("#filter-n").jqxComboBox("val");
                    //只有当第二个条件有效才加入连接符
                    resultField["filter2"] = $("#filter2").jqxComboBox('val');
                    resultField["filter2_arg"] = $("#filter2-arg").jqxInput("val");
                }
            }
        }
        var oldval = $("#allowselect").jqxGrid('getcellvalue', row, "measureFilter", resultField);

        $("#allowselect").jqxGrid('setcellvalue', row, "measureFilter", resultField);
        resultField = $("#allowselect").jqxGrid('getcellvalue', row, "measureFilter", resultField);
        //
        $("#filter-editor").jqxWindow("close");
    });

}


function initListBox() {}
//初始化所有btn对象
function initToolBar() {
    //查询需要提交的json结构体
    var serchData = {
        "yc": [],
        "yx": [],
        "yk": [],
        "yt": []
    };
    $(".toolbar-btn").jqxButton({
        width: '100',
        height: '20',
        theme: theme
    });
    $("#select-btn").on('click', function() {

        // $('#measure-select').show();

        $('#measure-select').jqxWindow('open');
    });
    $("#select-search").on('click', function() {
        serchData["begin"] = $('#timebegin').jqxDateTimeInput('getText');
        serchData["end"] = $('#timeend').jqxDateTimeInput('getText');
        alert(JSON.stringify(serchData));
    });
    $("#select-export").on('click', function() {
        alert("EXPORT");
    });
    //选择窗口-----不好操作
    //  new PopupLayer({
    ///      trigger : "#select-btn",
    //      popupBlk : "#measure-select",
    //     closeBtn : "#listOk",
    //      useFx : true,
    //     useOverlay : true,
    //     offsets : {
    //        x : 0,
    //        y : 30
    //    }
    // });
    //============================== 时间范围选择控件初始化
    $("#timebegin").jqxDateTimeInput({
        width: '200px',
        height: '20px',
        theme: theme,
        value: new Date(),
        formatString: "yyyy-MM-dd hh:mm:ss"
    }); //
    $("#timeend").jqxDateTimeInput({
        width: '200px',
        height: '20px',
        theme: theme,
        value: new Date(),
        formatString: "yyyy-MM-dd hh:mm:ss"
    });
    /*//区域时间选择，但是无法编辑，能够编辑的话使用还是比较方便的
    width: '450px',
     height: '25px',
     theme: 'energyblue',
     selectionMode: 'range',
          readonly: false,
     showFooter:true,
     formatString:"yyyy-MM-dd hh:mm:ss",
     enableBrowserBoundsDetection: true
  });
	*/
    $("#mSelectOK,#mSelectCancel").jqxButton({ //量测选择窗口按钮初始化
        width: '80',
        height: '20',
        theme: theme
    });

    $("#toggole-button").jqxButtonGroup({
        mode: 'radio',
        theme: "black",
        height: '42px'
    });
    //量测选择对话框点击确认，获取量测查询信息
    //select trval ,time from yc_scadasrv where id in( id1,id2);
    //首先确定时间范围 得到临时表1
    //然后查询ID范围   
    //按照按照ID进行值的过滤
    //行列转换

    //结构---服务端建立对应的类进行解析
	//提交参数包括如下：
    //begin
    //end
    //yc
    //yx
    //yt
    //yk
    $("#mSelectOK").on('click', function() {

        var rows = $("#treeGrid").jqxTreeGrid('getRows');
        var rowsData = "";


        //清空表格初始化数据
        columnsT = new Array();
        datafields = new Array();
        columngroups = new Array();

        //******************************
        var column = {};
        column["text"] = "时间";
        column["width"] = 120;
        column["cellsalign"] = 'center';
        column["datafield"] = "d_time";
        columnsT.push(column);

        var field = {};
        field["name"] = "d_time";
        datafields.push(field);
        //******************************
        //yc:[{globalid:[],filter:[]}]
        //yc:{gid:filter,gid:filter}

        var traverseTree = function(rows) {

            for (var i = 0; i < rows.length; i++) {
                // 获取被选择的leaf
                if (rows[i].checked) {

                    // rowsData += rows[i].name + "\n";
                    var measureCount = 0; //设备分组，下属量测大于0，添加该设备分组
                    for (var measitem in measureType) {
                        //	"id" : "d_1",
                        //    "measureName" : "高压母线yc",
                        //    "measureFilter" : '{"filter1":"<","filter1_arg":"5"}',
                        //    "measureisSelect" : true
                        var meatypeCount = 0; //量测类型分组计数，大于0，则添加该设备对应的量测分组
                        $(rows[i]["select-measure"][measitem]).each(function() {
                            rowsData += measitem;

                            if (this.measureisSelect) {
                                meatypeCount++;
                                measureCount++;
                                var searchItem = {};
                                searchItem["gid"] = this.id;
                                searchItem["filter"] = JSON.parse(this.measureFilter);
                                //alert(this.measureFilter);
                                serchData[measitem].push(searchItem);
                                rowsData += "  " + this.measureName;
                                //================形成表格需要的数据
                                var column = {};
                                column["text"] = this.measureName;
                                column["width"] = 80;
                                column["align"] = 'center';
                                column["cellsalign"] = 'center';
                                column["datafield"] = this.id;
                                column["columngroup"] = measitem + rows[i].id;
                                columnsT.push(column);
                                //var columnGruup = {};
                                //columnGruup["text"] = rows[i].name;
                                //columnGruup["name"] = "d_"+rows[i].id;
                                //columnGruup["align"]= 'center';
                                //columnGruup["parentgroup"]= 'center';
                                //columngroups.push(columnGruup);
                                //放入定义数组
                                var field = {};
                                field["name"] = this.id;
                                datafields.push(field);

                            }

                        });
                        if (meatypeCount > 0) //量测分组
                        {
                            var columnGruup = {};
                            columnGruup["text"] = measureType[measitem];
                            columnGruup["name"] = measitem + rows[i].id;
                            columnGruup["align"] = 'center';
                            columnGruup["parentgroup"] = "d_" + rows[i].id; //设置父组为设备组
                            columngroups.push(columnGruup);
                        }

                        rowsData += "\n";
                    }
                    // rowsData += rows[i].name + "\n";
                    if (measureCount > 0) //设备分组
                    {
                        var columnGruup = {};
                        columnGruup["text"] = rows[i].name;
                        columnGruup["name"] = "d_" + rows[i].id;
                        columnGruup["align"] = 'center';
                        columngroups.push(columnGruup);
                    }
                }

                ////回调读取所有的子节点
                if (rows[i].records) {
                    traverseTree(rows[i].records);
                }
            }
        };
        traverseTree(rows);
        // alert(JSON.stringify(serchData));
        // alert(JSON.stringify(columngroups));
        //销毁表格重建表
        $('#datagrid').jqxGrid('destroy');
        $('<div  id="datagrid"> </div>').insertAfter("#tool");
        initHistoryTable("");

        $('#measure-select').jqxWindow('close');

    });
}

function initHistoryTable(url) {
   

    // prepare the data
    var source = {
        datatype: "json",
        datafields: datafields,
        id: 'id_0',
        //url : url
        localdata: {} //datagrid_data
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    $("#datagrid").jqxGrid({
        width: '100%',
        height: '589',
        pageable: true,
        theme: theme,
        // filterable : true,
        //  sortable : true,
        source: dataAdapter,

        ready: function() {
            $("#datagrid").jqxGrid('hidecolumn', 'name');
        },
        columnsresize: true,
        columns: columnsT,
        columngroups: columngroups

    });
}

//创建 量测选择窗口

function createMeasureSelectWindow() {

    //更改为treegrid的方式进行选择
    $('#measure-select').jqxWindow({
        showCollapseButton: true,
        resizable: false,
        maxHeight: 580,
        maxWidth: 950,
        minHeight: 200,
        minWidth: 200,
        height: 580,
        width: 950,
        theme: theme,
        //autoOpen: false,
        cancelButton: $("#mSelectCancel"),
        initContent: function() {
            // $('#tab').jqxTabs({ height: '100%', width:  '100%' });
            // $('#measure-select').jqxWindow('close');

            // $('#measure-tabs').jqxTabs({ theme: 'black',width: '100%', height: '100%',scrollable:false});

        }
    });

};
//==============================================================================
//=====初始化 量测选择列表设备树，点击对应的设备，在右侧的设备量测，列表中选择需要的量测。
function initTreeGrid() {

    var source = {
        dataType: "json",
        dataFields: [{
            name: "name",
            type: "string"
        }, {
            name: "allow-measure",
            type: "string"
        }, {
            name: "id",
            type: "number"
        }, {
            name: "children",
            type: "array"
        }, {
            name: "select-measure",
            type: "string"
        }],
        hierarchy: {
            root: "children"
        },
        localData: treeGridData,
        id: "id"
    };

    var dataAdapter = new $.jqx.dataAdapter(source, {
        loadComplete: function() {

        }
    });
    // create jqxTreeGrid.

    $("#treeGrid").jqxTreeGrid({
        source: dataAdapter,
        altRows: true,
        width: '48%',
        height: '500',
        checkboxes: true,
        theme: theme,
        ready: function() {
            $("#treeGrid").jqxTreeGrid('expandRow', '1');
            $("#treeGrid").jqxTreeGrid('expandRow', '2');

        },
        columns: [{
            text: "设1备",
            align: "center",
            dataField: "name",
            width: 250
        }, {
            text: "可选量1测",
            cellsAlign: "center",
            align: "center",
            hidden: true,
            dataField: "allow-measure",
            width: 100
        }, {
            text: "已选量2测",
            dataField: "select-measure",
            cellsAlign: "left",
            align: "center",
            width: 500,
            cellsRenderer: function(row, column, value, rowData) {
 
                var valueSTR = "";
      

                for (var i in measureType) {


                    var meastr = "",
                        measCount = 0;
                    $(value[i]).each(function() {

                        if (this.measureisSelect) {
                            //background-color:'+(measCount%2?"#0d0d0d":"#131313")+'
                            meastr += '<div style="float:left; width:80px;">' + this.measureName + '</div>';
                            //alert(meastr);
                            measCount++; //统计当前已经选择的量测数量
                        }

                    });
                    if (measCount > 0) //有量测数量才显示在tree中
                    {
                        valueSTR += '<div style="width:100%;">';
                        valueSTR += '<div style="float:left;width:90px">【' + measureType[i] + " 】[" + measCount + "]</div>";
                        valueSTR += "<div style='width:400px;foat:left'>" + meastr + "</div>";
                        valueSTR += "</div>";

                    }
                };


                return valueSTR;
            }
        }]
    });
}


///////////////////////////////////////////////
/////////////*********************/////////////
function initDeviceMeasureList() {


    var source = {
        dataType: "arry",
        dataFields: [{
                name: "measureName",
                type: "string"
            }, // Possible values: 'string', 'date', 'number', 'float', 'int', 'bool'.
            {
                name: "measureFilter",
                type: "object",
                format: ""
            }, {
                name: "id",
                type: "number"
            }, {
                name: "measureisSelect",
                type: "bool"
            }
        ],
        localdata: deviceMeasure.yc,
        id: "id"
    };

    var dataAdapter = new $.jqx.dataAdapter(source, {
        loadComplete: function() {

        }
    });
    // create jqxTreeGrid.
    // var filterrenderer = function (row, column, cellvalue) {
    //     var value = cellvalue.filter1+cellvalue.filter1_arg+cellvalue.filter_n+cellvalue.filter2+cellvalue.filter2_arg;
    //    return '<span style="margin: 6px 3px; font-size: 12px; float: right; font-weight: bold;">' + cellvalue + '</span>';
    // }
    $("#allowselect").jqxGrid({
        source: dataAdapter,
        // altRows: true,
        width: '100%',
        height: '470',
        selectionmode: 'checkbox',
        // editable: true,
        theme: theme,
        ready: function() //设置被选择的项
        {

        },

        columns: [{
            text: "量测",
            align: "center",
            dataField: "measureName",
            width: '48%',
            editable: false
        }, {
            text: "条件",
            cellsAlign: "center",
            align: "center",
            dataField: "measureFilter",
            width: '46%',
            columntype: 'button',
            cellsrenderer: function(row, feild, cellvalue) { //在表格渲染中，设置量测条件显示格式
                var rows = $('#allowselect').jqxGrid('getrows');
                //获取上次表格中的数据
                var value = "";

                if (typeof(cellvalue) == "string") //加载的数据转换格式为json字符串，需要处理
                    cellvalue = JSON.parse(cellvalue);

                value = cellvalue.filter1 ? '(' + VALUEFEILD + cellvalue.filter1 : "";
                value += cellvalue.filter1_arg ? cellvalue.filter1_arg + ')' : "";
                value += cellvalue.filter_n ? cellvalue.filter_n : "";
                value += cellvalue.filter2 ? '(' + VALUEFEILD + cellvalue.filter2 : "";
                value += cellvalue.filter2_arg ? cellvalue.filter2_arg + ')' : "";
                // var value = cellvalue.filter1+cellvalue.filter1_arg+cellvalue.filter_n+cellvalue.filter2+cellvalue.filter2_arg;            
                if (value == "")
                    value = "无";
                return value;
            },
            buttonclick: function(row, obj) {
                //  $("#filter-editor").jqxWindow("open");
                //显示量测条件设置对话框
                filterWindShow(row, obj);
            }
        }]

    });

    //绑定rowSelect事件，更新measureisSelect==========xxx rowSelect  s必须大写
    //event.args 参数中如果有row 表示为但row操作，如果没有row表示对表格所有rows操作。由于unselect中对所有rows操作的时候得到的rowindex是不可用的，
    //因此采用对row的判断来操作表格中的数据的是否被选择的状态。
    $('#allowselect').on("rowSelect", function(event) {
        var rows = $('#allowselect').jqxGrid('getrows');
        if (event.args.row) {
            event.args.row["measureisSelect"] = true;
        } else {

            $(event.args.rowindex).each(function() {
                rows[this]["measureisSelect"] = true;
            });
        }
        //动态同步treegrid中被选择的数据
        deviceMeasure[$(".tabs-item.select").attr("measureType")] = rows; //放入全局data当前选择的设备量测缓存
        $("#treeGrid").jqxTreeGrid('endUpdate');
        // alert("Row with bound index: " + event.args.rowindex + " has been selected");
    });
    $('#allowselect').on("rowUnselect", function(event) {
        var rows = $('#allowselect').jqxGrid('getrows');
        if (event.args.row) {
            event.args.row["measureisSelect"] = false;
        } else {

            for (var i = 0; i < rows.length; i++) {
                rows[i]["measureisSelect"] = false;
            }
        }
        deviceMeasure[$(".tabs-item.select").attr("measureType")] = rows; //放入全局data当前选择的设备量测缓存
        $("#treeGrid").jqxTreeGrid('endUpdate');
        // alert("Row with bound index: " + event.args.rowindex + " has been selected");
    });

    /////////////////////初始化tab事件,tab 切换的时候保存上一个tab的数据，并加载新的tab的数据到表格
    $(".tabs-item").on("click", function() {

        //$($(this).attr("measureType"));
        $(".tabs-item").each(function() { //取消上次选择的对象，并保存对象的数据
            if ($(this).hasClass("select")) //获取上一次被选择的tab
            {

                $(this).removeClass("select"); //取消之前的选择

                var rows = $('#allowselect').jqxGrid('getrows'); //获取当前表格的数据

                //===========对jqxgrid显示需要进行响应的数据处理
                var result = "";
                for (var i = 0; i < rows.length; i++) {
                    var row = rows[i];
                    if (typeof(rows[i]["measureFilter"]) == "object") //jqxgrid 加载数据的时候不能是object，所以存储数据的时候，转换为string

                    {
                        rows[i]["measureFilter"] = JSON.stringify(rows[i]["measureFilter"]); //将json的object 转换为string						                          
                    }
                    //alert(rows[i]["measureisSelect"]);
                    //   result += row.measureName + " " + row.measureFilter + " " + row.measureisSelect + " " + row.id + "\n";
                }
                //==================== alert(result);     
                //获取上次表格中的数据
                deviceMeasure[$(this).attr("measureType")] = rows; //放入全局data当前选择的设备量测缓存中    
            }
        });
        //将当前item设置为被选
        $(this).addClass("select");

        updateDeviceDataList($(this).attr("measureType")); //根据tab选项，更新当前可选量测表格的
    });
    ////////////////////////////////////////////////////////////////////// 
    //根据type类型，更新当前可选量测表格的数据，type在tab切换的时候，从tab标
    //签中获取，treegrid选择事件的时候，获取当前选择tab，然后再获取tab中的type attr属性
    function updateDeviceDataList(type) {

        source.localdata = deviceMeasure[type]; //加载当前选择tab对应的数据
        // $('#allowselect').jqxGrid('clearselection');
        // $("#allowselect").jqxGrid('clear');
        $("#allowselect").jqxGrid('updatebounddata', 'cells');
        var rows = $('#allowselect').jqxGrid('getrows');
        //获取上次表格中的数据
        //  measureData[$(this).attr("measureType")] = rows;
        //  var result = "";
        //设置row的选择状态
        for (var i = 0; i < rows.length; i++) {
            if (rows[i]["measureisSelect"]) {

                $("#allowselect").jqxGrid('selectrow', i);
            } else {
                $("#allowselect").jqxGrid('unselectrow', i);
            }
        }

    }

    ///////////////
    //rowUnselect 取消选择事件
    //获取 tab的选择项，更新当前tab的数据到对应的measure列表中。
    //function savedSelectMeasureToTreeGrid() {
    $('#treeGrid').on('rowUnselect', function(event) {

        var args = event.args;
        // row data.
        var row = args.row;
        // row key.
        var key = args.key;
        var rows = $('#allowselect').jqxGrid('getrows'); //获取当前表格的数据

        //===========对jqxgrid显示需要进行响应的数据处理
        var result = "";
        for (var i = 0; i < rows.length; i++) {
            var row = rows[i];
            if (typeof(rows[i]["measureFilter"]) == "object") //jqxgrid 加载数据的时候不能是object，所以存储数据的时候，转换为string

            {
                rows[i]["measureFilter"] = JSON.stringify(rows[i]["measureFilter"]); //将json的object 转换为string						                          
            }
            //alert(rows[i]["measureisSelect"]);
            //   result += row.measureName + " " + row.measureFilter + " " + row.measureisSelect + " " + row.id + "\n";
        }
        //==================== alert(result);     
        //获取当前tab对应的表格所显示的数据，并更新到deviceMeasure中
        deviceMeasure[$(".tabs-item.select").attr("measureType")] = rows; //放入全局data当前选择的设备量测缓存中 
        //deviceMeasure就是jqxTreeGrid中的数据，js中的数据是共享地址空间的。
        //$("#treeGrid").jqxTreeGrid('setCellValue', key, 'select-measure', deviceMeasure);
        $("#treeGrid").jqxTreeGrid('endUpdate'); //及时更新treegrid

    });
    //}
    ///////////////////////////////////////////////////////////
    //rowSelect 从tree中获取measure的列表，并显示在右侧列表显示表格中。
    //function loadSelectMeasureToTreeGrid() {
    $('#treeGrid').on('rowSelect', function(event) {

        var args = event.args;
        // row data.
        var row = args.row;
        // row key.
        var key = args.key;
        //获取当前选择的grid  select-measure字段的值
        deviceMeasure = $("#treeGrid").jqxTreeGrid('getCellValue', key, 'select-measure');
        //更新到量测可选列表中
        updateDeviceDataList($(".tabs-item.select").attr("measureType"));

    });


    //}
}